package cn.bellychang.ood.litejunit.v3.framework.manipulation;

import cn.bellychang.ood.litejunit.v3.framework.runner.Description;
import cn.bellychang.ood.litejunit.v3.framework.runner.Runner;

/**
 * @author ChangLiang
 * @date 2020/5/28
 */
public abstract class Filter {
    /**
     * A null <code>Filter</code> that passes all tests through.
     */
    public static Filter ALL= new Filter() {
        @Override
        public boolean shouldRun(Description description) {
            return true;
        }

        @Override
        public String describe() {
            return "all tests";
        }
    };

    /**
     * @param description the description of the test to be run
     * @return true if the test should be run
     */
    public abstract boolean shouldRun(Description description);

    /**
     * Invoke with a <code>Runner</code> to cause all tests it intends to run
     * to first be checked with the filter. Only those that pass the filter will be run.
     * @param runner the runner to be filtered by the receiver
     * @throws NoTestsRemainException if the receiver removes all tests
     */
    public void apply(Runner runner) throws NoTestsRemainException {
        if (runner instanceof Filterable) {
            Filterable filterable= (Filterable)runner;
            filterable.filter(this);
        }
    }

    public abstract String describe();
}
